﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace UBCon.Ribbon
{
    /// <summary>
    /// Represents a control that allows a user to select items from among its children.
    /// </summary>
    internal class TabControlSelector:Selector
    {
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------
        #region Constructors

        /// <summary>
        /// Initializes a new instance of UBCon.Ribbon.TabControlSelector class
        /// </summary>
        public TabControlSelector() 
        {
        }

        /// <summary>
        /// Default static constructor.
        /// </summary>
        static TabControlSelector() 
        {
            Type ownerType = typeof(TabControlSelector);
            DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(ownerType));
        }
        #endregion

        //------------------------------------------------------
        //
        //  Properties
        //
        //------------------------------------------------------
        #region Properties
        #endregion

        //------------------------------------------------------
        //
        //  Depenency Property Changed Callbacks
        //
        //------------------------------------------------------
        #region Depenency Property Changed Callbacks
        #endregion

        //------------------------------------------------------
        //
        //  Overrides
        //
        //------------------------------------------------------
        #region Overrides

        /// <summary>
        /// Creates or identifies the element that is used to display the given item
        /// </summary>
        /// <returns></returns>
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new TabItem();
        }

        /// <summary>
        /// Determines if the specified item is (or is eligible to be) its owner container.
        /// </summary>
        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            bool _isValid = item is TabItem;

            if (_isValid) 
            {
                TabItem tabItem = item as TabItem;
                tabItem.ParentSelector = this;
            }
            return _isValid;
            
        }

        /// <summary>
        /// Invoked when initialization is completed, and items are ready to be generated.
        /// </summary>
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            if (TemplatedParent != null && TemplatedParent is TabControl) 
            {
                _wrapperControl = TemplatedParent as TabControl;

                foreach (TabItem item in _wrapperControl.Items)
                {
                    Items.Add(item);    
                }
            }
        }
        #endregion

        //------------------------------------------------------
        //
        //  Virual members
        //
        //------------------------------------------------------
        #region Virual members

        #endregion

        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------
        #region Public Methods
        #endregion

        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------
        #region Internal Methods
        #endregion

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
        #region Private Methods
        #endregion

        //------------------------------------------------------
        //
        //  Event Handlers
        //
        //------------------------------------------------------
        #region Event Handlers
        #endregion

        //------------------------------------------------------
        //
        //  Fields
        //
        //------------------------------------------------------
        #region Fields

        internal TabControl _wrapperControl;
        #endregion

        //------------------------------------------------------
        //
        //  Events
        //
        //------------------------------------------------------
        #region Events
        #endregion

        //------------------------------------------------------
        //
        //  Commands
        //
        //------------------------------------------------------
        #region Commands
        #endregion

    }
}
